package com.example.restful.controller;

import com.example.restful.entity.Comment;
import com.example.restful.entity.Like;
import com.example.restful.entity.Status;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RestController
public class StatusController {
    public List<Status> getStatus(){
        List<Status> list=new ArrayList<>();

        Status status1=new Status();
        status1.setId(1);
        status1.setContent("编辑中");
        status1.setAuthor("user01");
        status1.setDate("2024-9-1");

        Status status2=new Status();
        status2.setId(2);
        status2.setContent("完成");
        status2.setAuthor("user02");
        status2.setDate("2024-9-2");

        Status status3=new Status();
        status3.setId(3);
        status3.setContent("已删除");
        status3.setAuthor("user03");
        status3.setDate("2024-9-3");

        list.add(status1);
        list.add(status2);
        list.add(status3);
        return list;
    }

    public List<Comment> getComments(){
        List<Comment> list=new ArrayList<>();

        Comment obj1=new Comment();
        obj1.setId(1);
        obj1.setContent("编辑中");
        obj1.setAuthor("obj01");
        obj1.setDate("2024-9-1");

        Comment obj2=new Comment();
        obj2.setId(2);
        obj2.setContent("完成");
        obj2.setAuthor("obj02");
        obj2.setDate("2024-9-2");

        Comment obj3=new Comment();
        obj3.setId(3);
        obj3.setContent("已删除");
        obj3.setAuthor("obj03");
        obj3.setDate("2024-9-3");

        list.add(obj1);
        list.add(obj2);
        list.add(obj3);
        return list;


    }
    public List<Like> getLikes(){
        List<Like> list=new ArrayList<>();

        Like obj1=new Like();
        obj1.setId(1);
        obj1.setUserId(2);
        obj1.setDate("2024-9-1");

        Like obj2=new Like();
        obj2.setId(2);
        obj2.setUserId(7);
        obj2.setDate("2024-9-2");

        Like obj3=new Like();
        obj3.setId(3);
        obj3.setUserId(9);
        obj3.setDate("2024-9-3");

        list.add(obj1);
        list.add(obj2);
        list.add(obj3);
        return list;
    }
    @GetMapping("/api/statuses")
    public List<Status> getLists(){
        return getStatus();
    }


    @PostMapping("/api/statuses")
    public List<Status> addStatus(@RequestBody Status entity){
        List<Status> list=getStatus();
        list.add(entity);
        return list;
    }


    @PostMapping("/api/statuses/{id}/comments")
    public List<Comment> addComment(@PathVariable Integer id, @RequestBody Comment entity){
        List<Comment> list=getComments();
        entity.setStatusId(id);
        list.add(entity);
        return list;
    }


    @PostMapping("/api/statuses/{id}/likes")
    public List<Like> addLike(@PathVariable Integer id, @RequestBody Like entity){
        List<Like> list=getLikes();
        entity.setStatusId(id);
        list.add(entity);
        return list;
    }

}
